package com.zzptc.mzb.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.zzptc.mzb.myapplication.entity.Shiping;
import com.zzptc.mzb.myapplication.service.ShipingService;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ShiPing extends AppCompatActivity {
    private static final String TAG = "ShiPing";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shiping);
        getQichePinpaiInfo();
    }
    private void getQichePinpaiInfo() {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://apis.juhe.cn/cook/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        //创建接口对象
        // QichePinpaiService qichePinpaiService=retrofit.create(QichePinpaiService.class);
        //调用接口对象中定义的方法
        // Call<Qichepingbai> call=qichePinpaiService.getAllpinpai("e2a68c9e52b375c386286cf9747bf6d9","c");
        //调用Call接口中的异步方法

        //http://apis.juhe.cn/cook/query?key=c56bf09771912dc1c36f758f04a67c1b&menu=%E8%A5%BF%E7%BA%A2%E6%9F%BF&rn=10&pn=3
        ShipingService shipingService=retrofit.create(ShipingService.class);
        Call<Shiping> call=shipingService.getAllShiping("c56bf09771912dc1c36f758f04a67c1b","%E8%A5%BF%E7%BA%A2%E6%9F%BF","10","0");

        call.enqueue(new Callback<Shiping>() {
            @Override
            public void onResponse(Call<Shiping> call, Response<Shiping> response) {
                Shiping body = response.body();
                Log.d(TAG, "onResponse: "+body.getResult().getData().get(0).getTitle());
            }

            @Override
            public void onFailure(Call<Shiping> call, Throwable t) {
                Log.d(TAG, "onFailure: "+t.getMessage());
            }
        });


    }
}

